<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* .checked{checked:checked
        } */
    </style>
</head>

<body>
    <button>全选</button>

    <button>不选</button>

    <button>反选</button>
    <br>
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <script>
        //获取input
        /*var btn = document.getElementsByTagName('button')
        var oInput = document.getElementsByTagName('input')
        for (var i = 0; i < btn.length; i++) {
            btn[i].onclick = function () {
                if (this.innerHTML === '全选') {
                    for (j = 0; j < oInput.length; j++) {
                        oInput[j].checked = true;
                    }
                }
                else if (this.innerHTML === '不选') {
                    for (j = 0; j < oInput.length; j++) {
                        oInput[j].checked = false;
                    }
                }
                else if (this.innerHTML === '反选') {
                    for (j = 0; j < oInput.length; j++) {
                        oInput[j].checked = !oInput[j].checked
                    }
                }
            }
        }*/
        //获取button 和 input 标签
        var btn = document.getElementsByTagName('button');
        var inputs = document.getElementsByTagName('input');
        //循环button 并给button 添加点击事件
        for (var i = 0; i < btn.length; i++) {
            btn[i].onclick = function () {
                //判断btn的内容
                if (this.innerHTML === '全选') {
                    //循环input 
                    for (var j = 0; j < inputs.length; j++) {
                        inputs[j].checked = true;
                    }
                }
                else if (this.innerHTML === '不选') {
                    for (var j = 0; j < inputs.length; j++) {
                        inputs[j].checked = false;
                    }
                }
                else if (this.innerHTML === '反选') {
                    for (var j = 0; j < inputs.length; j++) {
                        inputs[j].checked = !inputs[j].checked

                    }
                }
            }
        }



    </script>





</body>

</html>